
#include <iostream>
using namespace std;

#define MAXSIZE 20

//顺序栈的存储结构定义
struct SqStack{
    int elem[MAXSIZE];
    int top;
};

//顺序栈的基本操作

//InitStack(&S)
void InitStack(SqStack &S)
{
    S.top = 0;
}

//StackEmpty(S)
bool StackEmpty(const SqStack &S)
{
    return S.top == 0;
}

//Push(&S, e)
void Push(SqStack &S, int e)
{
    if(S.top == MAXSIZE) throw "Stack full";
    S.elem[S.top++] = e;
}

//Pop(&S, &e)
void Pop(SqStack &S, int &e)
{
    if(S.top == 0) throw "Stack empty";
    e = S.elem[--S.top];
}


int main()
{
    SqStack S;
    InitStack(S);
    Push(S, 1);
    Push(S, 2);
    Push(S, 3);
    Push(S, 4);

    while(!StackEmpty(S)){
        int e;
        Pop(S, e);
        cout << e << endl;
    }
    return 0;
}